package router

import (
	"beesoft.ink/application/garage/app/api"
	"beesoft.ink/application/garage/app/api/common"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	"github.com/spf13/viper"
)

func Init(c *echo.Echo) {
	router := c.Group("/api")

	AuthBefore(router)
	Common(router)
	Translation(router)

	r := router.Group("")
	r.Use(middleware.JWTWithConfig(middleware.JWTConfig{
		SigningKey: []byte(viper.GetString("server.key")),
		ContextKey: "token",
		// Claims:     &jwt.MapClaims{},
	}))

	AuthAfter(r)
	Category(r)
	Area(r)
	Garage(r)
	Vehicle(r)

	GarageFlow(r)
}

func AuthBefore(router *echo.Group) {
	r := router.Group("/auth")

	r.POST("/send-verification-code", api.Auth.SendVerificationCode) // 发送验证码
	r.POST("/login", api.Auth.Login)                                 // 登录
}
func Common(router *echo.Group) {
	r := router.Group("/common")

	r.GET("/categories", common.Garage.Categories) // 分类
	r.GET("/garages", common.Garage.Garages)       // 仓库
}
func Translation(router *echo.Group) {
	r := router.Group("/translation")

	r.GET("/ifly", common.Translation.Ifly)
	r.GET("/iflyv1", common.Translation.IflyV1)
	r.GET("/iflyn", common.Translation.IflyN)
	r.GET("/tencent", common.Translation.Tencent)
}

func AuthAfter(router *echo.Group) {
	r := router.Group("/auth")

	r.POST("/logout", api.Auth.Logout)
	r.GET("/profile", api.Auth.Profile)
}
func Category(router *echo.Group) {
	r := router.Group("/categories")

	r.GET("", api.Category.List)
	r.GET("/:id", api.Category.Show)
	r.POST("", api.Category.Store)
	r.PUT("/:id", api.Category.Update)
	r.DELETE("/:id", api.Category.Destroy)
}
func Area(router *echo.Group) {
	r := router.Group("/areas")

	r.GET("", api.Area.List)
	r.GET("/:id", api.Area.Show)
	r.POST("", api.Area.Store)
	r.PUT("/:id", api.Area.Update)
	r.DELETE("/:id", api.Area.Destroy)
}
func Garage(router *echo.Group) {
	r := router.Group("/garages")

	r.GET("", api.Garage.List)
	r.GET("/:id", api.Garage.Show)
	r.POST("", api.Garage.Store)
	r.PUT("/:id", api.Garage.Update)
	r.DELETE("//:id", api.Garage.Destroy)
}
func Vehicle(router *echo.Group) {
	r := router.Group("/vehicles")

	r.GET("", api.Vehicle.List)
	r.GET("/:id", api.Vehicle.Show)
	r.POST("", api.Vehicle.Store)
	r.PUT("/:id", api.Vehicle.Update)
	r.DELETE("/:id", api.Vehicle.Destroy)
}
